﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Lm.Common.Web
{
    public class WirteFileToClient
    {
        public void Write(byte[] buf, string sFileName)
        {
            HttpContext.Current.Response.ContentType = "application/octet-stream";
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(sFileName, Encoding.UTF8));
            HttpContext.Current.Response.AddHeader("Content-Length", buf.Length.ToString());

            HttpContext.Current.Response.BinaryWrite(buf);
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.Close();

        }
    }
}
